package cn.congzhou.crm.service.impl;

import cn.congzhou.crm.domain.SystemDictionary;
import cn.congzhou.crm.mapper.SystemDictionaryMapper;
import cn.congzhou.crm.query.QueryObject;
import cn.congzhou.crm.service.ISystemDictionaryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemDictionaryServiceImpl implements ISystemDictionaryService {

    @Autowired
    private SystemDictionaryMapper systemDictionaryMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        if(id!=null){
            systemDictionaryMapper.deleteByPrimaryKey(id);
        }
        return 0;
    }


    @Override
    public SystemDictionary selectByPrimaryKey(Long id) {
        SystemDictionary sysDic = systemDictionaryMapper.selectByPrimaryKey(id);
        return sysDic;
    }

    @Override
    public List<SystemDictionary> selectAll() {
        List<SystemDictionary> sysDic = systemDictionaryMapper.selectAll();
        return sysDic;
    }

    @Override
    public void saveOrUpdate(SystemDictionary sysDic) {
        if(sysDic.getId()!=null){
            systemDictionaryMapper.updateByPrimaryKey(sysDic);
        }else {
            systemDictionaryMapper.insert(sysDic);
        }
    }

    @Override
    public PageInfo<SystemDictionary> selectByPage(QueryObject qo) {
//      调用这个类的静态方法处理分页数据
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<SystemDictionary> list = systemDictionaryMapper.selectByPage(qo);
//      创建页面信息对象封装起来
        PageInfo<SystemDictionary> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
